var whois = {
	root: 'http://whois.pconline.com.cn',
    version:2.0,
    alertIp:function(ip){
        var s=document.getElementsByTagName('head')[0].appendChild(document.createElement("script"));
        s.src=this.root+"/jsAlert.jsp?ip="+ip;
    },
    lableIp:function(id,ip){
        var s=document.getElementsByTagName('head')[0].appendChild(document.createElement("script"));
        s.src=this.root+"/jsLabel.jsp?callback=jsShow&ip="+ip+"&id="+id;
    }
}

function loading(){
	$("#current_ip").html('['+IPData[0]+']');
	searchip(IPData[0],"local");
	$("#result_box").hide();
}

function searchInfoByIp(){
	var keyword=$("#input_box").val();
	if(!check(keyword)){
		return;
	
}

function jsShow(local){
	console.log(local);
}


function check(ip){
var pattern=/^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/;
flag_ip=pattern.test(ip);
	if(!flag_ip){
			alert("IP地址输入非法!");
			return false;
	}else{
		$("#result_box").show();
		//whois.lableIp("searchresult",keyword);
		searchip(ip);
	}
}}

function searchip(ip,flag){
	var s=document.getElementsByTagName('head')[0].appendChild(document.createElement("script"));
	if(flag!="local"){
		s.src="http://api.ipinfodb.com/v3/ip-city/?key=526bcb53ba1f851f8dd72152caadc92526145db4e91aaa36c503aeea9240cfe9&ip="+ip+"&format=json&callback=getdetailip";
	}else{
		s.src="http://api.ipinfodb.com/v3/ip-city/?key=526bcb53ba1f851f8dd72152caadc92526145db4e91aaa36c503aeea9240cfe9&ip="+ip+"&format=json&callback=getlocalip";
	}
}

function getdetailip(ipdetail){
	var locallanguage=window.localStorage.getItem("url");
	var keyword=$("#input_box").val();
	if(locallanguage=="zh-cn"){
		whois.lableIp("searchresult",keyword);
	}else{
		$("#searchresult").html(ipdetail.countryName+"    "+ipdetail.cityName); 
	}
}

function getlocalip(ipdetail){
	var locallanguage=window.localStorage.getItem("url");
	if(locallanguage=="zh-cn"){
		whois.lableIp("current_source",IPData[0]);
	}else{
		$("#current_source").html(ipdetail.countryName+"    "+ipdetail.cityName);
	}
}

function androidphoneadddiv(){
	if(equipment=="androdiphone"){
		document.getElementById("ip_container").className="androdiphone";
	}
	
}